﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xyz.BusinessObjects;
using Xyz.DataObjects.Interfaces;

namespace Xyz.DataObjects.Entity.Dao
{
    public class EntityMemberDao : IMemberDao
    {
        public int GetMemberPoints(int customerId)
        {
            using (var context = EntityObjectFactory.CreateContext())
            {
                var member = context.CustomerEntities.OfType<MemberEntity>().Single(x => x.CustomerId == customerId);

                return member.MemberPoints;
            }
        }

        public void AddMemberPoints(int customerId, int points)
        {
            using (var context = EntityObjectFactory.CreateContext())
            {
                var member = context.CustomerEntities.OfType<MemberEntity>().Single(x => x.CustomerId == customerId);
                member.MemberPoints += points;

                context.SaveChanges();
            }
        }
    }
}
